<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            position: fixed;
            top: 100px;
            left: 0;
            width: 200px;
            height: 200px;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <button id="start">start</button>
    <button id="stop">stop</button>
    <div id="box"></div>
</body>
<script>
var startBtn = document.getElementById("start");
var endBtn = document.getElementById("stop");
var box = document.getElementById("box");

var nowLeft = 0;
var timer;

startBtn.onclick = function(){
    clearInterval(timer);
    timer = setInterval(moveFuc,1000);
}
endBtn.onclick = function(){
    clearInterval(timer);
}

function moveFuc(){
    if(nowLeft > 500){
        nowLeft = 0;
    }else{
        nowLeft += 50;
    }
    box.style.left = nowLeft + "px";
}

</script>

</html>